import React from 'react';

import { Company as Component } from '@/pagesComponents/Company';
import { env } from '@/shared/constants';
import { CompanyDto } from '@/shared/interfaces/generated';
import { getImageUrl } from '@/shared/lib/images';
import { generateMetaData } from '@/shared/lib/meta';
import { GetServerSideProps } from 'next';
import Head from 'next/head';

export default function Company({ data }: { data: CompanyDto }) {
  const { title, logo } = data;
  return (
    <>
      <Head>{generateMetaData({ title, image: getImageUrl(logo) })}</Head>
      <Component />
    </>
  );
}
export const getServerSideProps: GetServerSideProps = async (context) => {
  const id = context.params?.id;
  const res = await fetch(`${env.apiUrl}/companies/${id}`);
  const data = await res.json();
  if (typeof id !== 'string' || data?.statusCode) {
    return {
      notFound: true,
    };
  }
  return {
    props: {
      data,
    },
  };
};
